const db = wx.cloud.database();
var util = require("../../utils/util.js")
Page({
  options: {
    addGlobalClass: true,
  },
  data: {
    deadLine:wx.getStorageSync('deadLine'),
    themeColor:'blue',
    ScreenBrightness:0.5,
    showHome:false,
    cardCur: 0,
    swiperList: [{
      id: 0,
      type: 'image',
      url: 'https://nos.netease.com/edu-image/6532F1F91352870E9578ED44E42AA55C.jpg?imageView&thumbnail=240y150&quality=100'
    }, {
      id: 1,
        type: 'image',
        url: 'https://nos.netease.com/edu-image/96922A8F3017C98CF51134726843BB4B.jpg?imageView&thumbnail=480y270&quality=100',
    }, {
      id: 2,
      type: 'image',
      url: 'https://nos.netease.com/edu-image/500D30C149E61FFD49E616D6872583BD.jpg?imageView&thumbnail=240y150&quality=100'
    }],
    isClock:false,
    colorStyle01:"background-color: #3a7938; box-shadow: 0rpx 0rpx 50rpx 10rpx #62886cad;",
    colorStyle02:"background-color: #8ebee2;box-shadow: 0rpx 0rpx 50rpx 10rpx #8dd2dfad;",
    // iconList: [{
    //   icon: 'list',
    //   color: 'red',
    //   name: '题库'
    // }, {
    //   icon: 'creative',
    //   color: 'orange',
    //   name: '学习新闻'
    // }, {
    //   icon: 'edit',
    //   color: 'yellow',
    //   badge: 0,
    //   name: '题目练习'
    // }, 
    // {
    //   icon: 'video',
    //   color: 'yellow',
    //   badge: 0,
    //   name: '视频课程'
    // },{
    //   icon: 'appreciate',
    //   color: 'olive',
    //   badge: 22,
    //   name: '关于我们'
    // }],
    iconList: [
      {
        // icon: 'video',
        // color: 'yellow',
        // badge: 0,
        // name: '视频课程'
      },  
      {
        icon: 'edit',
        color: 'yellow',
        badge: 0,
        name: '开始作业'
      }, 
  {
      icon: 'calendar',
      color: 'orange',
      name: '作业成绩'
    },
  //  {
  //     icon: 'appreciate',
  //     color: 'olive',
  //     badge: 22,
  //     name: '关于我们'
    // }
  ],
    gridCol:4,
    cur : 0,
    avatarUrl: '',
    userInfo: {},
    userName: 'null',
    userClass: 'null',
    elements: [{
        title: '题库',
        name: 'answer',
        icon: 'question',
        color: 'blue'
      },
      {
        title: '学习教材',
        name: 'order',
        icon: 'like',
        color: 'red'
      },
      {
        title: '练习',
        name: 'exercise',
        icon: 'copy',
        color: 'cyan'
      },
      {
        title: '视频课程',
        name: 'video',
        icon: 'video',
        color: 'green'
      },
      {
        title: '关于',
        name: 'about',
        icon: 'settings',
        color: 'pink'
      },
    ]
  },  
  goshequ(e){
    var index = e.currentTarget.dataset.id
    if(index == 1){
      wx.navigateTo({
        url: '/pages/exercise/exercise',
      })
      return
    }
    if(index == 2){
      wx.navigateTo({
        url: '/pages/achievement/achievement',
      })
    }
  },
  toClockin(){
    var TIME = util.formatTime(new Date());
    var place = ''
    var that = this
    wx.getLocation({
        type: 'wgs84', // 默认为 wgs84 返回 gps 坐标，gcj02 返回可用于 wx.openLocation 的坐标
        success: function (res) {
          //赋值经纬度
        //  console.log(res,"=====这里是地址");
       
        wx.request({
          url: "https://apis.map.qq.com/ws/geocoder/v1/?location=" + res.latitude + "," + res.longitude + "&key=LPIBZ-UFCHF-7VZJF-NHUDV-YC7WK-5VFNH",
          success:res=>{
            place=res.data.result.address
            that.setData({
              isClock:true,
              time: TIME,
              place: place
            })
            db.collection('attend').get({
              success: res => {
                console.log(that.data.time,'======地址')
                db.collection('attend').doc(res.data[0]._id).update({
                  data: {
                    time:that.data.time,
                    name:that.data.userName,
                    place:that.data.place
                  },
                  fail:res=>{
                    console.log("失败了耶")
                  },
                  success:res=>{
                    // console.log("成功了耶",res)
                    db.collection('attend').get({success:res=>{console.log(res);}})
                  }
                })
              }
            })
          }
        })
        wx.showToast({
          title: '成功',
          icon: 'success',
          duration: 1000//持续的时间
     
        })
        }
      })

},
  onLoad: function(options) {
    db.collection('userInfo').get({
      success: res => {
        console.log(res)
        this.setData({
          userInfo: res.data[0].userInfo,
          avatarUrl: res.data[0].avatarUrl,
          userName: res.data[0].name,
          userClass: res.data[0]._class,
        })
      }
    })
    
  },
})